package PCLockRefine;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

public class PrintNumThread extends Thread {

    private Lock lock;
    private Condition condition;

    public PrintNumThread(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    @Override
    public void run() {

        try {
            sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        lock.lock();
        for (int i = 1; i < 53; i++) {
            System.out.print(i);
            if (i % 2 == 0) {
                condition.signal();
                try {
                    condition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        lock.unlock();
    }
}
